package com.ygo.feihua.adapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import android.content.Context;
import com.ygo.feihua.Gongju;
import android.view.LayoutInflater;
import com.ygo.feihua.R;
import android.widget.TextView;

public class AdapterAddcard extends BaseAdapter
{
	
	private List<Map<String,Object>> data=new ArrayList<Map<String,Object>>();
	private Zujian zujian;
	private Gongju gj;
	private Context context;
	
	public AdapterAddcard(Context context, List<Map<String,Object>> data){
		this.context=context;
		this.data=data;
		gj=Gongju.getdx(context);
	}
	public void sx(List<Map<String,Object>> data){
		this.data=data;
		notifyDataSetInvalidated();
	}
	public void add(Map<String,Object> map){
		data.add(map);
		notifyDataSetChanged();
	}
	public void del(Map<String,Object> map){
		for(int i=0;i<data.size();i++){
			if(data.get(i).equals(map)){
				data.remove(i);
				notifyDataSetChanged();
				return;
			}
		}
	}
	class Zujian{
		TextView ac_name,ac_km;
	}
	
	public List<Map<String,Object>> getdata(){
		return data;
	}
	
	
	@Override
	public int getCount()
	{
		// TODO: Implement this method
		return data.size();
	}

	@Override
	public Object getItem(int p1)
	{
		// TODO: Implement this method
		return data.get(p1);
	}

	@Override
	public long getItemId(int p1)
	{
		// TODO: Implement this method
		return p1;
	}

	@Override
	public View getView(int position, View p2, ViewGroup p3)
	{
		if(p2==null){
			zujian=new Zujian();
			p2=LayoutInflater.from(context).inflate(R.layout.item_addcard,null);
			zujian.ac_name=(TextView) p2.findViewById(R.id.ac_name);
			zujian.ac_km=(TextView) p2.findViewById(R.id.ac_km);
			
			p2.setTag(zujian);
		}else{
			zujian=(AdapterAddcard.Zujian) p2.getTag();
		}
		zujian.ac_name.setText((String)data.get(position).get("name"));
		zujian.ac_km.setText((String)data.get(position).get("km"));
		
		
		// TODO: Implement this method
		return p2;
	}
	
	
	
}
